package com.bus

import org.groovyflow.db.*

class ProductDao{
	
	def static findAll(){
		 {sql -> sql.rows("select * from productx", [])}
     }
	
	
	def static findById(id){
		 {sql -> sql.rows("""select productx.*, category.name as categoryname 
				 from productx, category where productx.categoryid = category.id 
				 and productx.id = ?""", 
				[id])[0]}
	}
	
	def static update(product){
	   {sql ->
		sql.executeUpdate("update productx set price = ?, description = ? where id = ?", 
				[product.price, product.description, product.id])
      }
	}
	
	
	
}